//
// Created by Administrator on 2023/7/28.
//
#include <iostream>
#include <vector>

using namespace std;

class Solution {
public:
    vector<int> leftRightDifference(vector<int> &nums) {
        // 先构造左右数组
        int n = nums.size();
        vector<int> leftSum = vector<int>(n, 0);
        vector<int> rightSum = vector<int>(n, 0);
        for (int i = 1; i < n; ++i) {
            leftSum[i] = nums[i - 1] + leftSum[i - 1];
        }
        for (int i = n - 2; i >= 0; --i) {
            rightSum[i] = nums[i + 1] + rightSum[i + 1];
        }
        vector<int> ans = vector<int>(n, 0);
        for (int i = 0; i < n; ++i) {
            ans[i] = abs(leftSum[i] - rightSum[i]);
        }
        return ans;
    }
};

int main() {
    vector<int> nums{10, 4, 8, 3};
    Solution s;
    auto ans = s.leftRightDifference(nums);
    for (auto &x: ans) {
        cout << x << endl;
    }
}
